package com.hp.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @author hp
 */

@Getter
@AllArgsConstructor
public enum ExcelCellTypeEnum {


    TEXT(1, "text", "Please input text."),
    DATE(2, "date", "Please input the date. Format:YYYY/MM/DD."),
    POSITIVE_INTEGER(3, "positive_integer", "Please input positive integers."),
    INTEGER(4, "integer", "Please input integers."),
    SELECT(5, "select", "Please select from the dropdown menu."),

    ;

    private final int id;
    private final String type;
    private final String description;


    public static ExcelCellTypeEnum fromByType(String type) {
        for (ExcelCellTypeEnum cellTypeEnum : values()) {
            if (StringUtils.equals(cellTypeEnum.getType(), type)) {
                return cellTypeEnum;
            }
        }
        return null;
    }

    public static String getDescByType(String type) {
        ExcelCellTypeEnum anEnum = fromByType(type);
        return Objects.isNull(anEnum) ? "" : anEnum.getDescription();
    }

}
